import { merge } from 'lodash';
import { setLocalStorage, getLocalStroage } from '@/util/index.js'
import { toRaw } from 'vue';

const layout = {
  namespaced: true,
  state(){
    return {
      isExpandMenu: false, // 是否折叠menu菜单
      isRefresh: true, // 是否刷新
      defaultOpeneds: ['1','1-1','16','16-1'],
      styleOptions: {
        layoutType: getLocalStroage('styleOptions') && getLocalStroage('styleOptions').layoutType ? getLocalStroage('styleOptions').layoutType : 'vertical', // 布局
        theme: getLocalStroage('styleOptions') && getLocalStroage('styleOptions').theme ? getLocalStroage('styleOptions').theme : 'defaultTheme', // 主题
        showTabs: getLocalStroage('styleOptions') ? getLocalStroage('styleOptions').showTabs : true, // 是否展示标签
        showTabsIcon: getLocalStroage('styleOptions') ? getLocalStroage('styleOptions').showTabsIcon : true, // 是否展示标签图标
        isFixedHead: getLocalStroage('styleOptions') ? getLocalStroage('styleOptions').isFixedHead : true, // 是否固定头部
        showInternationalIcon: getLocalStroage('styleOptions') ? getLocalStroage('styleOptions').showInternationalIcon : true, // 是否展示国际化图标
        showRefreshIcon: getLocalStroage('styleOptions') ? getLocalStroage('styleOptions').showRefreshIcon : true, // 是否展示刷新图标
        showScreen: getLocalStroage('styleOptions') ? getLocalStroage('styleOptions').showScreen : true, // 是否展示全屏
      },
    }
  },
  actions: {},
  mutations: {
    setExpandMenu(state){
      state.isExpandMenu = !state.isExpandMenu;
    },
    setRefresh(state) {
      state.isRefresh = false;
      setTimeout(()=>{
        state.isRefresh = true;
      }, 500);
    },
    setStyleOptions(state,options) {
      merge(state.styleOptions, options);
      setLocalStorage('styleOptions', options);
    },
    // 主题恢复默认
    setDefaultStyleOptions(state) {
      state.styleOptions.showTabs = true;
      state.styleOptions.showTabsIcon = true;
      state.styleOptions.isFixedHead = true;
      state.styleOptions.showInternationalIcon = true;
      state.styleOptions.showRefreshIcon = true;
      state.styleOptions.showScreen = true;
      setLocalStorage('styleOptions', toRaw(state.styleOptions));
    },
    setDefaultOpeneds(state, options){
      merge(state.defaultOpeneds, options);
    }
  },
}
export default layout;